﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SRD.Model.SRD.DTO;
using SRD.Model.SRD.Util;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Web.UI.WebControls;
using System.Configuration;

namespace SRD.Model.SRD.DAO
{
    class TelefoneEmpresaDAO
    {
        public Boolean inserirTelefoneEmpresa(TelefoneEmpresaDTO telefone)
        {
            SqlCommand cmd = new SqlCommand("insert into TELEFONE_EMPRESA(NUMERO, EMPRESA_ID) values (@numero, @empresaId);", Conexao.getConexao());
            try
            {

                Conexao.getConexao().Open();


                cmd.Parameters.Add("@numero", SqlDbType.Int).Value = telefone.numero;
                cmd.Parameters.Add("@empresaId", SqlDbType.Int).Value = telefone.empresaId;
                cmd.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                Conexao.getConexao().Close();
            }
        }

        public DataSet getTelefoneEmpresa(int empresaId)
        {
                       
            try
            {
                Conexao.getConexao().Open();
                SqlCommand cmd = new SqlCommand("Select * from TELEFONE_EMPRESA where EMPRESA_ID = @empresaId", Conexao.getConexao());
                cmd.Parameters.Add("@empresaId", SqlDbType.Int).Value = empresaId;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet DT = new DataSet();
                da.Fill(DT,"TELEFONE_EMPRESA");
                DataSet retorno = DT;
                return retorno;
            }
            finally
            {
                Conexao.getConexao().Close();
            }


        }

        public Boolean alterarTelefoneEmpresa(TelefoneEmpresaDTO telefone)
        {
            SqlCommand cmd = new SqlCommand("UPDATE TELEFONE_EMPRESA SET NUMERO = @numero WHERE (TELEFONE_EMPRESA_ID = @telefoneId)", Conexao.getConexao());

            try
            {
                Conexao.getConexao().Open();
                cmd.Parameters.Add("@numero", SqlDbType.Int).Value = telefone.numero;
                cmd.Parameters.Add("@telefoneId", SqlDbType.Int).Value = telefone.telefoneEmpresaId;
                cmd.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                Conexao.getConexao().Close();
            }
        }
    }
}
